
$(document).ready(function(){
    for(var ii =0; ii < $("input[name='rolelistnum']").val();ii++)
    {
        $('#a'+ii).qtip({
                content: {
                    text: $('.tooltiptext'+ii),
                    title: '权限详细信息'
                },
                style: {
                    classes: 'qtip-blue qtip-shadow'
                }
            });

    }


    $("#oper").val(geturlparam("oper") );
    //$("input[name='id']").val(geturlparam("id"));
    $("#id").val(geturlparam("id"));
    $("#userinfo").validate({
        rules:{
            username:{
                required:true,
                maxlength:20,
                minlength:3
            },
            companyname:{
                required:true,
                maxlength:20,
                minlength:3
            },
            roleid:{
                required:true
            },
            nickname:{
                required:true,
                maxlength:12,
                minlength:3
            },
            phonenumber:{
                required:true,
                maxlength:16,
                minlength:1,
                number:true
            },
            email:{
                required:true,
                maxlength:32,
                minlength:1,
                email:true
            },
            pwd:{
                required:true,
                maxlength:24,
                minlength:3
            },
            pwd1:{
                required:true,
                maxlength:24,
                minlength:3,
                equalTo:pwd
            }
        },
        errorClass: "help-inline",
        errorElement: "span",
        highlight:function(element, errorClass, validClass) {
            $(element).parents('.control-group').addClass('error');
        },
        unhighlight: function(element, errorClass, validClass) {
            $(element).parents('.control-group').removeClass('error');
            $(element).parents('.control-group').addClass('success');
        },

        submitHandler: function(form) {  //通过之后回调
            var param = $("#userinfo").serialize();
            $.ajax({
                url : "userinfo.html",
                type : "post",
                dataType : "json",
                data: param,
                success : function(result) {
                    bootbox.dialog({
                        message: "<STRONG class=\"red\">"+result.info+"</STRONG>  <BR><BR>不继续操作则跳转到权限分级管理。继续操作吗？",
                        title: "权限分级管理",
                        buttons: {
                            success: {
                                label: "继 续",
                                className: "btn-success",
                                callback: function() {
                                    /*if(result.status=="success")
                                     form.reset();*/
                                }
                            },
                            danger: {
                                label: "取 消",
                                className: "btn-danger",
                                callback: function() {
                                    window.location.href='useradmin.html';
                                }
                            }
                        }
                    });


                }
            });
        },
        invalidHandler: function(form, validator) {  //不通过回调
            return false;
        }
    });



});
